package com.projectmanagement.model.data;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name = "Projects")
public class Project implements Serializable {

	private static final long serialVersionUID = 2866941649424482002L;

	@Id
	@Column(name = "id")
	@GeneratedValue
	private long id;

	@Column(name = "name", nullable = false)
	private String name;

	@Column(name = "priority", nullable = false)
	private PriorityLevel priority;

	@Column(name = "description", nullable = false)
	private String description = "";

	@Column(name = "show_description_in_overview", nullable = true)
	private boolean showDescription = false;

	@Column(name = "logo_file", nullable = true)
	private String logoFile = "";

	@Column(name = "completed_on", nullable = false)
	private Timestamp completedOn = new Timestamp(0);

	@Column(name = "completed_by_id", nullable = true)
	private User completedBy;

	@Column(name = "created_on", nullable = false)
	private Timestamp createdOn = new Timestamp(0);

	@Column(name = "created_by_id", nullable = true)
	private User createdBy;

	@Column(name = "updated_on", nullable = false)
	private Timestamp updatedOn = new Timestamp(0);

	@Column(name = "updated_by_id", nullable = true)
	private User updatedBy;

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "PROJECT_COMPANIES", joinColumns = { @JoinColumn(name = "project_id", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "company_id", referencedColumnName = "id") })
	private List<Company> companies;

	@OneToMany(fetch = FetchType.LAZY)
	private List<ProjectFile> files;

	@OneToMany(fetch = FetchType.LAZY)
	private List<ProjectUser> users;

	public Project() {
	}

	public Project(String name) {
		this();
		this.name = name;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public PriorityLevel getPriority() {
		return priority;
	}

	public void setPriority(PriorityLevel priority) {
		this.priority = priority;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public boolean isShowDescription() {
		return showDescription;
	}

	public void setShowDescription(boolean showDescription) {
		this.showDescription = showDescription;
	}

	public String getLogoFile() {
		return logoFile;
	}

	public void setLogoFile(String logoFile) {
		this.logoFile = logoFile;
	}

	public Timestamp getCompletedOn() {
		return completedOn;
	}

	public void setCompletedOn(Timestamp completedOn) {
		this.completedOn = completedOn;
	}

	public User getCompletedBy() {
		return completedBy;
	}

	public void setCompletedBy(User completedBy) {
		this.completedBy = completedBy;
	}

	public Timestamp getCreatedOn() {
		return createdOn;
	}

	public void setCreatedOn(Timestamp createdOn) {
		this.createdOn = createdOn;
	}

	public User getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(User createdBy) {
		this.createdBy = createdBy;
	}

	public Timestamp getUpdatedOn() {
		return updatedOn;
	}

	public void setUpdatedOn(Timestamp updatedOn) {
		this.updatedOn = updatedOn;
	}

	public User getUpdatedBy() {
		return updatedBy;
	}

	public void setUpdatedBy(User updatedBy) {
		this.updatedBy = updatedBy;
	}

	public List<Company> getCompanies() {
		return companies;
	}

	public void setCompanies(List<Company> companies) {
		this.companies = companies;
	}

	public List<ProjectFile> getFiles() {
		return files;
	}

	public void setFiles(List<ProjectFile> files) {
		this.files = files;
	}

	public List<ProjectUser> getUsers() {
		return users;
	}

	public void setUsers(List<ProjectUser> users) {
		this.users = users;
	}

}
